﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Xml.Linq;
using System.Collections.ObjectModel;
using System.Text;

namespace JYRWPH
{
    public partial class Detail : PhoneApplicationPage
    {
        public Detail()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            IDictionary<string, string> parameters = this.NavigationContext.QueryString;

            if (parameters.ContainsKey("link"))
            {
                string link = parameters["link"];


                //获取列表
                XElement xDoc = XElement.Load(String.Format("db/{0}", link));
                XElement xC = xDoc.Element("channel");

                //title
                PageTitle.Text = xC.Element("title").Value.ToString();

                //description
                WebBrowser PageContent = new WebBrowser();
                PageContent.NavigateToString(ConvertExtendedASCII("<meta name=\"viewport\" content=\"user-scalable=no\" />" + xC.Element("description").Value.ToString()));
                //PageContent.Visibility = Visibility.Visible;
                ContentPanel.Children.Add(PageContent);
            }
            base.OnNavigatedTo(e);
        }
        //private static string ConvertExtendedASCII(string HTML)
        //{
        //    string retVal = "";
        //    char[] s = HTML.ToCharArray();

        //    foreach (char c in s)
        //    {
        //        if (Convert.ToInt32(c) > 127)
        //            retVal += "&#" + Convert.ToInt32(c) + ";";
        //        else
        //            retVal += c;
        //    }

        //    return retVal;
        //}
        public static string ConvertExtendedASCII(string HTML)
        {
            StringBuilder str = new StringBuilder();
            char c;
            for (int i = 0; i < HTML.Length; i++)
            {
                c = HTML[i];
                if (Convert.ToInt32(c) > 127)
                {
                    str.Append("&#" + Convert.ToInt32(c) + ";");
                }
                else
                {
                    str.Append(c);
                }
            }
            return str.ToString();
        }

    }
}